<template>
	<view class="container">
		<view class="tab-wrap">
			<view class="tab-item" :class="[tabIndex == index ? 'tab-item-act':'']" v-for='(item,index) in tabList'
				:key="index" @tap='switchTab(index)'>{{item}}</view>
		</view>
		<view class="wrap" v-if='showPage'>
			<view class="list-wrap" v-if='list.length > 0'>
				<view class="list-item" v-for="(item,index) in list" :key="index">
					<view class="top-order line-v-center">
						<view class="order-sn">订单编码：{{item.task_number}}</view>
						<view class="status line-center" v-if='item.status == 0'>待领取</view>
						<view class="status line-center" v-if='item.status == 1'>待洽谈</view>
						<view class="status line-center" v-if='item.status == 2'>洽谈中</view>
						<view class="status status2 line-center" v-if='item.status == 3' @tap='pushTask(item.task_id)'>重新发布</view>
						<view class="status line-center" v-if='item.status == 4'>已完成</view>
					</view>
					<view class="b-wrap">
						<view class="b-item">
							<view class="text">贡献值</view>
							<view class="num">{{item.contribution}}</view>
						</view>
						<view class="b-item">
							<view class="text">金额</view>
							<view class="num">{{item.money}}</view>
						</view>
						<view class="b-item">
							<view class="text">开始时间</view>
							<view class="num">{{item.publish_time ? item.publish_time : '--'}}</view>
						</view>
						<view class="b-item">
							<view class="text">结束时间</view>
							<view class="num">{{item.end_time ? item.end_time : '--'}}</view>
						</view>
					</view>
				</view>
			</view>
			<no-data v-else class="noData"></no-data>
		</view>
	</view>
</template>

<script>
	const app = getApp();
	export default {
		data() {
			return {
				tabList: ["待领取", "待洽谈", "洽谈中", "未完成", "已完成"],
				tabIndex: 0,
				showPage: false,
				page: 1,
				totalPage: 1,
				list: [],
				loadEnd: false,
			};
		},
		onLoad(option) {
			this.tabIndex = option.index ? option.index : 0;
			this.getList()
		},
		onPullDownRefresh() {
			this.clear();
			uni.stopPullDownRefresh()
		},
		methods: {
			clear(){
				this.list = [];
				this.getList()
			},
			switchTab(index){
				this.tabIndex = index;
				this.clear()
			},
			getList() {
				const that = this;
				uni.showLoading({
					title:'加载中...',
					mask:true
				})
				app.globalRequest({
					api: app.getApi().task.taskBuyList,
					data: {
						status: this.tabIndex,
						// page: that.page,
						// limits: 15
					}
				}).then(res => {
					this.showPage = true;
					if (res.code == 0) {
						that.list = res.data;
					}
				})
			},
			pushTask(id){
				app.globalData.againTaskId = id;
				uni.switchTab({
					url:'/pages/push-task/push-task'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		width: 100%;
		min-height: 100vh;
		background: #F6F7FB;
	}

	.tab-wrap {
		width: 100%;
		height: 84rpx;
		background: #FFFFFF;
		position: fixed;
		left: 0;
		top: 0;
		z-index: 22;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0 26rpx;
		box-sizing: border-box;
	}

	.tab-item {
		font-size: 24rpx;
		color: #AEAEAE;
	}

	.tab-item-act {
		color: #333;
		position: relative;

		&::after {
			content: '';
			width: 50rpx;
			height: 4rpx;
			background: #212121;
			position: absolute;
			left: 0;
			right: 0;
			margin: auto;
			bottom: -10rpx;
		}
	}

	.wrap {
		padding-top: 112rpx;
		padding-bottom: 30rpx;
	}

	.list-wrap {
		margin: 0 24rpx;
	}

	.list-item {
		background: #fff;
		border-radius: 8rpx;
		overflow: hidden;
		margin-bottom: 24rpx;

		.top-order {
			padding: 0 24rpx;
			height: 88rpx;
			background: linear-gradient(342deg, #F6F7FB 0%, #E2E2E2 100%);
			justify-content: space-between;
			position: relative;

			&:before {
				content: '';
				width: 85rpx;
				height: 75rpx;
				background: url(@/static/no-icon.png) no-repeat;
				background-size: 100% 100%;
				position: absolute;
				left: 0;
				top: 0;
				bottom: 0;
				margin: auto;
			}

			.status {
				width: 136rpx;
				height: 48rpx;
				background: #C5C5C5;
				border-radius: 24rpx;
				color: #fff;
				font-size: 24rpx;
			}
			.status2{
				background: #212121;
			}
		}

		.b-wrap {
			// padding:0 24rpx;
			padding-right: 24rpx;
			padding-top: 36rpx;
			padding-bottom: 26rpx;
			display: grid;
			grid-template-columns: repeat(4, 150rpx);
			justify-content: space-between;

			.b-item {
				// border-right: 1px solid red;
			}

			.text {
				text-align: center;
			}

			.num {
				text-align: center;
				margin-top: 20rpx;
			}
		}
	}
</style>